function layAuth(){
    $(".authClass").each(function(){
        var str = $(this).attr('lay-auth')
        var user = JSON.parse(sessionStorage.getItem("userInfo"))
        var permissions = user.authInfo.sys_usercenter;
        if(!permissions){
            $(this).hide()
        }else{
            var isExit = $.inArray(str, permissions)
            if(isExit == -1){
                $(this).hide()
            }
        }
    });
}

$.ajaxSetup({
    complete: function (XMLHttpRequest, textStatus) {
        console.log(XMLHttpRequest);
        var redirect = XMLHttpRequest.getResponseHeader("Redirect");
        if (redirect == "true") {
            window.location.href = XMLHttpRequest.getResponseHeader("RedirectUrl");
        }
    },
    dataFilter:function (response) {
        if(isJSON(response)){
            var jsonData = JSON.parse(response);
            if(jsonData.code == 501){
                window.location.href = "/"
            }else{
                return response;
            }
        }else{
            return response;
        }
    }

});

function isJSON(str) {
    if (typeof str == 'string') {
        try {
            var obj=JSON.parse(str);
            if(typeof obj == 'object' && obj ){
                return true;
            }else{
                return false;
            }

        } catch(e) {
            return false;
        }
    }
}
